<template>
	<view class="shadowBox" @click="closeModel()" catchtouchmove="move">
		<view class="showModel" @click.stop>
			<view class="title">提 示</view>
			<view class="content">订阅消息需用户授权后才能使用，请点击继续</view>
			<view class="btn">
				<button class="left" @click="closeModel()">取消</button>
				<button class="right" @click="newsEvent()">继续</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			};
		},
		props: ['template'],
		methods:{
			closeModel(){
				this.$emit("closeModel",false);
				this.$emit("rejectEvent", 0);
			},
			newsEvent(){
				// var template1 = ['lqrjTIJrm8U6v1zBZCJbwHtKfDUGLOHn7Tmr2y9iRdc','xCzTkoAsqowm1mZ-o_yGK0r7zBcDusUSPY4le3Isxg0'];
				var template0 = this.template[0];
				wx.requestSubscribeMessage({
				  tmplIds: this.template,
				  success:(res)=>{ 
					  console.log(res);
					  if(res.errMsg == 'requestSubscribeMessage:ok'){
					  		if(res[template0] == 'accept'){
								uni.showToast({
									title: '订阅消息成功!'
								})
					  		};
					  		if(res[template0] == 'reject'){
								uni.showToast({
									icon: 'none',
									title: '您拒绝了授权，请重新授权才能使用此服务!'
								});
								this.$emit("rejectEvent", 0);
					  		};					  
					  }
					  
				  }
				})
				this.$emit("closeModel",false);
			}
		}
	}
</script>

<style lang="scss">
	.shadowBox{
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		z-index: 999;
		background-color: rgba(0,0,0,.3);
		.showModel{
			position: relative;
			width: 85%;
			height: 360upx;
			background-color: #fff;
			border-radius: 15upx;
			margin: 0 auto;
			margin-top: 400upx;
			overflow: hidden;
			.title{
				font-size: 30upx;
				text-align: center;
				margin-top: 45upx;
				font-weight: bold;
			}
			.content{
				color: #a9a9aa;
				font-size: 34upx;
				text-align: center;
				padding: 35upx 40upx 0 40upx;
			}
			.btn{
				position: absolute;
				left: 0;
				bottom: 0;
				width: 100%;
				display: flex;
				.left,.right{
					width: 50%;
					height: 100upx;
					line-height: 100upx;
					border-top: 2upx solid #f6f6f6;
					font-size: 32upx;
					text-align: center;
					background-color: #fff;
					color: #000;
					border-radius: 0;
					font-weight: bold;
				}
				.right{
					color: #495b86;
					border-left: 2upx solid #f6f6f6;
				}
			}
		}
	}
</style>
